<link rel='stylesheet' href='<?php echo base_url();?>css/calendar.css' title='calendar'>

<script language="javascript" src="<?php echo base_url();?>js/calendar.js"></script>

<script language="javascript">

//***** Function formating the Date for inputbox *****

function fnSetDateFormat(oDateFormat)
{
	oDateFormat['FullYear'];		//Example = 2007
	oDateFormat['Year'];			//Example = 07
	oDateFormat['FullMonthName'];	//Example = January
	oDateFormat['MonthName'];		//Example = Jan
	oDateFormat['Month'];			//Example = 01
	oDateFormat['Date'];			//Example = 01
	oDateFormat['FullDay'];			//Example = Sunday
	oDateFormat['Day'];				//Example = Sun
	oDateFormat['Hours'];			//Example = 01
	oDateFormat['Minutes'];			//Example = 01
	oDateFormat['Seconds'];			//Example = 01

	var sDateString;
	
	return sDateString;
}

$(document).ready(function(){
    $("#mod_id").change(function(){
        var mod_id = $(this).val();
        $.ajax({
	    	   type: "POST",
	    	   url:"<?php echo  base_url();?>model/get_category",
	    	   data: "mod_id="+mod_id,
	    	   success: function(msg){
	    		   $("#category_id").html("");
		    	   $("#category_id").html(msg);
	    	   }
	    	});
        if(mod_id==""){
      	   var str="<font color='red'>请选择型号！</font>";
             $("#mod_id_notice").html('');
             $("#mod_id_notice").html(str);
             return false;
         }else{
      	   $("#mod_id_notice").html('');
         }
    })

    
    $("#category_id").change(function(){
       var category_id=$(this).val();
       $.ajax({
    	   type: "POST",
    	   url:"<?php echo  base_url();?>model/get_version",
    	   data: "category_id="+category_id,
    	   success: function(msg){
    		   $("#version_id").html("");
	    	   $("#version_id").html(msg);
    	   }
    	});
       if(category_id==""){
    	   var str="<font color='red'>请选择类别！</font>";
           $("#category_id_notice").html('');
           $("#category_id_notice").html(str);
           return false;
       }else{
    	   $("#category_id_notice").html('');
       }
	})

	  $("#version_id").change(function(){
		  var mod_id=$("#mod_id").val();
		  var category_id=$("#category_id").val();
          var version_id=$(this).val();
          if(version_id==""){
          	   var str="<font color='red'>请选择类别！</font>";
                 $("#version_id_notice").html('');
                 $("#version_id_notice").html(str);
                 return false;
             }else{
          	   $("#version_id_notice").html('');
             }
       $.ajax({
    	   type: "POST",
    	   url:"<?php echo  base_url();?>model/get_version_detail",
    	   data: "version_id="+version_id+"&mod_id="+mod_id+"&category_id="+category_id,
    	   success: function(msg){
        	 //库存量  
	    	   $("#pre_count").val(msg);
	    	   $("#count_notice").html("<font color='red'>此版本库存量仅剩"+msg+"本</font>");
    	   }
    	});
	})
	
	
	$("#company_id").change(function(){
		var company_id=$(this).val();
        if(company_id==""){
        	   var str="<font color='red'>请选择发放公司！</font>";
               $("#company_id_notice").html('');
               $("#company_id_notice").html(str);
               return false;
           }else{
        	   $("#company_id_notice").html('');
           }
	})
	
    $("#submit").click(function(){
        var mod_id=$("#mod_id").val();
        var category_id=$("#category_id").val();  
        var version_id=$("#version_id").val(); 
        var company_id=$("#company_id").val(); 
        var pre_count = $("#pre_count").val();
        var count = $("#count").val();
        var codes = $("#codes").val();
        if(mod_id==""){
     	   var str="<font color='red'>请选择型号！</font>";
            $("#mod_id_notice").html('');
            $("#mod_id_notice").html(str);
            return false;
        }
        if(category_id==""){
     	   var str="<font color='red'>请选择类别！</font>";
            $("#category_id_notice").html('');
            $("#category_id_notice").html(str);
            return false;
        }
        if(version_id==""){
       	   var str="<font color='red'>请选择版本！</font>";
              $("#version_id_notice").html('');
              $("#version_id_notice").html(str);
              return false;
          }
        if(codes == "" ){
        	var str="<font color='red'>请输入发放单据号！</font>";
            $("#codes_notice").html('');
            $("#codes_notice").html(str);
            return false;
        }else{
       	 $("#codes_notice").html('');
            }
        if(company_id == "" ){
        	var str="<font color='red'>请选择发放公司！</font>";
            $("#company_id_notice").html('');
            $("#company_id_notice").html(str);
            return false;
        }
        if(count==''){
        	var str="<font color='red'>请输入发放数量！</font>";
            $("#count_notice").html('');
            $("#count_notice").html(str);
            return false;
        }else if(count>pre_count){
        	var str="<font color='red'>发放数量不能大于库存！</font>";
            $("#count_notice").html('');
            $("#count_notice").html(str);
            return false;
        }        
     })	

})

</script>
		<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>model/send_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">首页</a> /<?php echo anchor('model/send_add','添加资料发放');?></div>
			</div>
			
		  <div class="table add_table">
				
				<input type="hidden" id="pre_count" value="">
				<table class="listing form" cellpadding="0" cellspacing="0">
				  <?php if(isset($id)){echo form_open('model/send_edit/'.$id);}else{echo form_open('model/send_add');}?>
				  <?php if(isset($id)){?><input type='hidden' value='<?php echo $send->count;?>' name='pre_count'/>
				  <input type='hidden' value='<?php echo $send->version;?>' name='pre_version'/>
				  <input type='hidden' value='<?php echo $send->mod_id;?>' name='mod_id'/>
				  <input type='hidden' value='<?php echo $send->category_id;?>' name='category_id'/>
				  <input type='hidden' value='<?php echo $send->version_id;?>' name='version_id'/>
				  <?php }?>
					<tr>
						<th  colspan="2"  align="center"><?php if(isset($id)){?>编辑资料发放<?php }else{?>新增资料发放<?php }?></th>
					</tr>
					<tr>
						<td class="first" width="172"><strong>型号：</strong></td>
						<td class="last"><select name="mod_id" id="mod_id" <?php if(isset($id)){ ?>disabled=true <?php }?>>
						                   <option value="">请选择型号</option>
						                   <?php foreach($mod as $k=>$val):?>
						                     <option value="<?php echo $val->mod_id;?>" <?php if(isset($id)){ if($val->mod_id==$send->mod_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php endforeach;?>
						                 </select><span id="mod_id_notice"></span><?php if(isset($id)){ ?><font color="#FF0000">编辑状态下，型号，资料种类，资料版本不可以更改</font><?php }?></td>
					</tr>
					<tr>
						<td class="first" width="172" ><strong>资料种类：</strong></td>
						<td class="last"><select name="category_id" id="category_id"  <?php if(isset($id)){ ?>disabled=true <?php }?> >
					                         	<option value="">请选择资料种类</option>
						                  <?php if(isset($id)){?>
						                   <?php foreach($category as $k=>$val):?>
						                     <option value="<?php echo $val->category_id;?>" <?php if(isset($id)){ if($val->category_id==$send->category_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php  endforeach;}?>
						                 </select><span id="category_id_notice"></span></td>
					</tr>
					<tr>
						<td class="first" width="172"><strong>资料版本：</strong></td>
						<td class="last"><select name="version_id" id="version_id"  <?php if(isset($id)){ ?>disabled=true <?php }?>>					                       
						                    	<option value="">请选择资料版本</option>
						                 <?php if(isset($id)){?>   	
						                   <?php foreach($version as $k=>$val):?>
						                     <option value="<?php echo $val->version_id;?>" <?php if(isset($id)){ if($val->version_id==$send->version_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php  endforeach;}?>
						                 </select><span id="version_id_notice"></span></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>发放单据号：</strong></td>
						<td class="last"><input type="text" class="text" name="codes" id="codes" value="<?php if(isset($id)){echo $send->codes;}?>" /><span id="codes_notice"></span></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>发往单位：</strong></td>
						<td class="last"><select name="company_id" id="company_id" <?php if(isset($id)){ if($send->is_update==1){ ?>disabled=true <?php }}?>>
						                   <option value="">请选择资料版本</option>
						                   <?php foreach($company as $k=>$val):?>
						                     <option value="<?php echo $val->company_id;?>" <?php if(isset($id)){ if($val->company_id==$send->company_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php endforeach;?>
						                 </select><span id="company_id_notice"></span> </td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>发放份数：</strong></td>
						<td class="last"><input type="text" class="text" <?php if(isset($id)){ if($send->is_update==1){ ?>disabled=true <?php } }?> name="count" id="count" value="<?php if(isset($id)){echo $send->count;}?>" onKeyUp="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" onafterpaste="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" /><span id="count_notice"></span></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>备注：</strong></td>
						<td class="last"><textarea name="des" cols="80" rows="5"><?php if(isset($id)){echo $send->des;}?></textarea></td>
					</tr>
					<tr>
						<td colspan="2" style="text-align:center;"><input type="submit" value="提交" class="button" id="submit"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回" class="button" onclick="location.href='<?php echo site_url()?>model/send'" /></td>			
					</tr>
				</form>	
				</table>
	        <p>&nbsp;</p>
		  </div>
		</div>
	</div>
	<div id="footer"></div>
</div>



</body>
</html>
